<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet"  type="text/css"  href="/lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet"  type="text/css" href="/css/goodslist.css">
    <link rel="stylesheet" href="/css/liandou.css">
</head>
<body>

<div class="goodslist-wrapper" style="padding: 0 30px 0 30px">

    <div>
        <div class="row czrow" >
            <form class="col-sm-4 form-inline">
                <div class="form-group">
                    <input type="text" class="form-control"  placeholder="用户名" name="search">
                    <button class="btn btn-primary" type="submit">搜索</button>
                </div>
            </form>

            <div class="col-sm-4"><a href="javascript:;" class="btn btn-default"><span class="glyphicon glyphicon-repeat"></span>刷新-共 <i>{$list}</i> 条记录 </a> </div>

        </div>
        <div class="tab-content">
            <form action="">
                <table class="table "style="text-align: center">
                    <thead style="border: 1px solid #BBBBBB;background-color:#eeeeee;" >
                    <tr style="border-bottom: 1px solid #BBBBBB">
                        <td>用户名</td>
                        <td>银行账号</td>
                        <td>用户当前联豆数量</td>
                        <td>操作</td>
                    </tr>
                    </thead>
                    <tbody>
                        {foreach name="beanUsers" item="user"}
                            <tr>
                            <td >
                                <span  class="phone">{$user['username']}</span><br>
                            </td>
                            <td>
                                {if condition="$user->bankAccount->isEmpty()"}
                                    <p class="">暂无绑定银行账号</p>
                                {elseif condition="(count($user->bankAccount->toArray()) eq 1) AND ($user->bankAccount->toArray()[0]['bind_staff'] eq 1)"/}
                                    <p class="">银行账号已解绑</p>
                                {elseif condition="(count($user->bankAccount->toArray()) eq 1) AND ($user->bankAccount->toArray()[0]['bind_staff'] eq 0)"/}
                                    <p class="">{$user->bankAccount->toArray()[0]['bank_num']}</p>
                                    <p><i>{$user->bankAccount->toArray()[0]['bank_name']}</i><i>({$user->bankAccount->toArray()[0]['name']})</i></p>
                                {elseif condition="count($user->bankAccount->toArray())>1" /}
                                    {foreach name="($user->bankAccount->toArray())" key="k" item="it"}
                                        {if condition="$it['bind_staff'] == 0"}
                                        <p class="">{$it['bank_num']}</p>
                                        <p><i>{$it['bank_name']}</i><i>({$it['name']})</i></p>
                                        <?php break; ?>
                                {/if}
                                    {/foreach}
                                {/if}
                            </td>
                            <td>
                                <div class="count">{$user['beans']}</div>
                            </td>
                            <td>
                                <ul>
                                    <li><a href="javascript:;" class="btn btn-default btn-xs editbtn"  data-toggle="modal" data-target="#caozuomodel"
                                    >操作</a></li>
                                    <li><a href="{:url('admin/beans/beansShow',['username'=>$user['username']])}" class="btn btn-default btn-xs">详情</a></li>
                                    <!--<li><a href="javascript:;" class="btn btn-default btn-xs">删除</a></li>-->
                                </ul>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                {$beanUsers->render()}
            </form>

        </div>
    </div>
</div>

<div class="modal fade" id="caozuomodel" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">联豆管理-操作</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="{:url('admin/beans/beanUserUpdate')}" method="post">
                    <div class="form-group">
                        <label  class="col-sm-3 control-label" style="vertical-align: top">用户名：</label><span class="col-sm-9 " id="username" ></span>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label" style="vertical-align: top">联豆数量：</label><span class="col-sm-9 " id="beancount" ></span>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">操作：</label>
                        <div class="col-sm-9">
                            <input type="text" class="textbox" id="textbox" name="asBeanNum">
                            <button type="button" class="btn btn-info" id="add">增加</button>
                            <button type="button" class="btn  btn-info " id="cut">减少</button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">操作后数量：</label>
                        <div class="col-sm-9">
                            <label id="text"></label>
                            <input type="hidden" name="username" value="">
                            <input type="text"  name="count"  hidden value="">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="sub">确认操作</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="/lib/jquery/jquery.js"></script>
<script src="/lib/bootstrap/js/bootstrap.min.js"></script>
<script>
    $(".editbtn").each(function (index, item) {
        $(item).click(function () {
            $("#textbox").val("");
            $("#username").html("");
            $("#beancount").html("");
            var phone=$($(".phone").get(index)).html();
            var beancount=$($(".count").get(index)).html();
            $("#username").html(phone);
            $("input[name=username]").val(phone);
            $("#inputphone").val(phone);
            $("#beancount").html(beancount);
        })
    });
    /*计算数量*/
    $("#add").click(function () {
        var beforeval=Number($("#beancount").html());
        var value=Number($("#textbox").val());

        if(!value)return;
        if(!/^\d+$/g.test(value)){
            alert("请输入数字！");
            return
        }
        $("#text").html(beforeval+value);
        $("input[name=count]").val(beforeval+value);
        console.log($("input[name=count]").val());
    });
    $("#cut").click(function () {
        var beforeval=Number($("#beancount").html());
        var value=Number($("#textbox").val());

        if(!value)return;
        if(!/^\d+$/g.test(value)){
            alert("请输入数字！");
            return
        }

        $("#text").html(beforeval-value);
        $("input[name=count]").val(beforeval-value);
    });
/*提交*/
    $("#sub").click(function () {
        if(!$("input[name=count]").val()){
            alert("请输入增加或减少数量");
            return false
        }
    });
    $(".Remarks").each(function (index,item) {
        var value="";
        $(this).focus(function () {
            value=$($(".Remarks").get(index)).val();
        });
        $(this).blur(function () {
            var valueafter=$($(".Remarks").get(index)).val();
            var order_num = $($(".phone").get(index)).html();
            if(value!==valueafter){
                $.ajax({
                    url:"remarks",
                    data:{"remarks":valueafter, 'order_num':order_num},
                    type:"post",
                    success:function (val) {
                        console.log(val)
                    }
                })
            }
        })
    });


</script>
</body>
</html>
